﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSCop.Core;

namespace DSCop
{
    public class CommandLineArgumentsParser
    {
        public CommandArguments Parse(string[] args)
        {
            if (args.Count() < 1)
            {
                throw new CommandArgumentsException("Missing job file name.");
            }

            CommandArguments arguments = new CommandArguments();

            arguments.FileName = args[0];
            if (arguments.FileName.StartsWith("-") || arguments.FileName.StartsWith("/"))
            {
                throw new CommandArgumentsException("Missing job file name.");
            }

            IList<string> ruleList = null;
            for (int i = 1; i < args.Count(); i++)
            {
                if (args[i].ToUpper() == "-INCLUDE")
                {
                    ruleList = arguments.IncludeRules;
                }
                else if (args[i].ToUpper() == "-EXCLUDE")
                {
                    ruleList = arguments.ExcludeRules;
                }
                else
                {
                    if (ruleList == null)
                    {
                        throw new CommandArgumentsException("Missing -include/-exclude switch");
                    }

                    ruleList.Add(args[i]);
                }
            }

            return arguments;
        }
    }
}
